package com.leostadyn.stackfarm.timestatistics.net.interceptor;

import android.os.Build;

import com.orhanobut.hawk.Hawk;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

public class HeaderInterceptor implements Interceptor {
    @Override
    public Response intercept(Chain chain) throws IOException {
        Request originalRequest = chain.request();
        Request.Builder header = originalRequest.newBuilder();
        if (Build.VERSION.SDK_INT > 13) {
            header.addHeader("Connection", "close");
        }
        String token = Hawk.get("token", null);
        if (token != null)
            header.addHeader("access-token", token);
        Request requestWithUserAgent = header.build();
        return chain.proceed(requestWithUserAgent);
    }
}
